package main

import "fmt"

// 空接口作为函数参数
func show(a interface{}) {
	fmt.Printf("type:%T value:%v\n", a, a)
}

func justifyType(x interface{}) {
	switch v := x.(type) {
	case string:
		fmt.Printf("x is a string，value is %v\n", v)
	case int:
		fmt.Printf("x is a int is %v\n", v)
	case bool:
		fmt.Printf("x is a bool is %v\n", v)
	default:
		fmt.Println("unsupport type！")
	}
}

func main() {
	fmt.Println("空接口 ")
	fmt.Println(`空接口是指没有定义任何方法的接口。因此任何类型都实现了空接口。

	空接口类型的变量可以存储任意类型的变量。`)
	var k1 interface{}
	fmt.Printf("%T\n", k1)
	var k3 map[string]interface{}
	k3 = make(map[string]interface{}, 50)

	k3["name"] = "wjp"
	k3["age"] = 12
	k3["isgo"] = true
	k3["hobby"] = []string{"吃", "喝"}
	fmt.Println(k3)

	k1 = "Hello 沙河"
	v, ok := k1.(string)
	if ok {
		fmt.Println(v)
	} else {
		fmt.Println("类型断言失败")
	}

	justifyType("dshfkla")
	justifyType(12)
	justifyType(false)
	justifyType([]int{1, 2})

}
